"""
@File         : router.py
@Time         : 2024/05/10 21:44:44
@Author       : Qrj
@Email        : 923207736@qq.com
@Description  : 站内信记录相关路由
"""

from typing import Annotated

from fastapi import APIRouter, Depends

from src.business.admin.system.oauth2.token.dependencies.no_introduction import (
    DependVerifyAccessTokenMenumPermission,
)
from src.enums.permission_operation import PermissionOperationEnum
from src.utils.unified_response import SuccessApiJSONResponse

from .dependencies.route_depend import (
    route_depend_delete_station_message_record,
    route_depend_get_station_message_record,
    route_depend_get_user_self_unread_station_message_record_count,
    route_depend_list_get_user_self_station_message_record,
    route_depend_list_station_message_record,
    route_depend_update_self_station_message_record_read_status,
)
from .schemas.out import StationMessageRecordCompleteOutSchema

# 构建权限验证相关的依赖项
# 查
depend_select_permission_verify = DependVerifyAccessTokenMenumPermission(
    __file__, PermissionOperationEnum.select.value
)
# 删
depend_delete_permission_verify = DependVerifyAccessTokenMenumPermission(
    __file__, PermissionOperationEnum.delete.value
)


# 创建路由
router = APIRouter(
    prefix="/admin/system/station-message/record",
    tags=[
        "站内信记录接口",
    ],
)


@router.get("/get", summary="查询单个站内信记录")
async def route_get_station_message_record(
    verify_menu_permission: Annotated[None, Depends(depend_select_permission_verify)],
    station_message_record: Annotated[
        StationMessageRecordCompleteOutSchema,
        Depends(route_depend_get_station_message_record),
    ],
):
    return SuccessApiJSONResponse(data=station_message_record)


@router.post("/list", summary="查询站内信记录列表")
async def route_list_station_message_record(
    verify_menu_permission: Annotated[None, Depends(depend_select_permission_verify)],
    list_result: Annotated[
        tuple[list[StationMessageRecordCompleteOutSchema], int],
        Depends(route_depend_list_station_message_record),
    ],
):
    search_pagination_result, search_total = list_result
    data = {"result": search_pagination_result, "total": search_total}
    return SuccessApiJSONResponse(data=data)


@router.post("/list-self", summary="查询自身站内信记录列表")
async def route_list_get_user_self_station_message_record(
    list_result: Annotated[
        tuple[list[StationMessageRecordCompleteOutSchema], int],
        Depends(route_depend_list_get_user_self_station_message_record),
    ],
):
    search_pagination_result, search_total = list_result
    data = {"result": search_pagination_result, "total": search_total}
    return SuccessApiJSONResponse(data=data)


@router.get("/get-unread-count", summary="查询当前用户未读的站内信记录数量")
async def route_get_user_self_unread_station_message_record_count(
    unread_count: Annotated[
        int, Depends(route_depend_get_user_self_unread_station_message_record_count)
    ],
):
    return SuccessApiJSONResponse(data=unread_count)


@router.post("/update-read-status", summary="修改用户自身站内信记录的已读状态")
async def route_update_self_station_message_record_read_status(
    update_read_status_operation: Annotated[
        None, Depends(route_depend_update_self_station_message_record_read_status)
    ],
):
    return SuccessApiJSONResponse(message="修改用户自身站内信记录的已读状态成功")


@router.post("/delete", summary="删除站内信记录")
async def route_delete_station_message_record(
    verify_menu_permission: Annotated[None, Depends(depend_delete_permission_verify)],
    delete_operation: Annotated[
        None, Depends(route_depend_delete_station_message_record)
    ],
):
    return SuccessApiJSONResponse(message="删除站内信记录成功")
